/*********************************************************************
 * img_stab_if_R.h
 * ABOUT : Implementation of IS.
 * AUTHOR : Dilawar Singh
 * Written on : April 15, 2010
 * Modified on : April 29, 2010 
 (c) Dilawar Singh, 2010
 **********************************************************************/

#ifndef _IMG_STAB_R_H_
#define _IMG_STAB_R_H_

#include <vector>
#include "stabilize_config.h"
#include "is_quaternion_R.h"
#include "is_homography_R.h"
#include "is_homography_matrix_R.h"

#include "app_engine/video_module/algo_if/af_algo_if/KalmanFilter.h"
#include "app_engine/video_module/algo_if/af_algo_if/cam_motion_mgr.h"
#include "app_engine/video_module/algo_if/af_algo_if/CamMotion.h"
#include "app_engine/video_module/video_handler/video_handler.h"
#include "core_engine/iob/monitor/hdmi/monitor_pipeline.h"

//#define MAX_SIZE 1024 //is this used?
#define MAX_LENGTH 1024
#define QUAT_LENGTH 4
#define SUB_LENGTH 4
#define H_MATRIX_LENGTH 9
#define R_MATRIX_LENGTH 9
#define K_MATRIX_LENGTH 9

class img_stab_if_R : public IsHomographyR
{
private:
    cam_motion_mgr* pObjCamMotionManager;
    //CamMotion* pObjCamMotion;
    //KalmanFilter *pObjKalmanFilter;
	static video_handler* pBaseVideoHandler;

    ULONG lastVsyncTimeStamp;       // Time stamp of Vsync
    ULONG lastMotionTimeStamp;      // Time stamp of 

public:
        
    kalmanType camInternalmatrix[9]; // camera internal matrix.
    kalmanType arrayQuaternions[MAX_LENGTH][QUAT_LENGTH]; // array of quaternions.
    
    kalmanType arrayCamInternalMatrix[2*9]; // array for curCamera and nextCamera.
    kalmanType arrayTwoQuaternion[2*QUAT_LENGTH];  // array for current and 
    	
    /* declare the arrays of pointers to hold these values. */
    vector<kalmanType>  myParamVec; 
    vector<kalmanType> myFilteredVec;
    // for s, theta and t.
    vector<kalmanType> myVecS;
    vector<kalmanType> myVecT;
    vector<kalmanType> myVecTheta;
   
public:
    // Set Base interface.
	static int initInterface(video_handler* pVideoHandler);
	
	/* Constructor */ 
    img_stab_if_R();
    img_stab_if_R(kalmanType *pArrayQuat, kalmanType *pArrayCamMat);

    /* Destructor */
    virtual ~img_stab_if_R();

    /*
     * Run Image stabilizer.
     */
    void runImageStabilizeR(void);
    /* 
     * This finction will accumulate the s, theta and T values in a queue.
     */
    vector<kalmanType> accParamsInQueue(kalmanType *pimgSThetaT, vector<kalmanType>);
    /* 
     */  
    vector<kalmanType> calcSmoothMotion(vector<kalmanType> myParamVec);
    
    /* 
     * This function will give us smoothen s, theta and T.
     */
    vector<kalmanType> getSmoothenParams(vector<kalmanType>, int filterLength); 

    friend class KalmanFilter;
    friend class cam_motion_mgr;
    friend class CamMotion;
    
};

#endif
